package mn.more.wits.server.model;

import java.util.HashMap;
import java.util.Map;

/**
 * in-memory storage of all accounts that have special "status" such as "disabled", "inactive", etc.  If a particular
 * user is not found in this repository, then it means normal -- status=active.
 *
 * @author <a href="mailto:mike.liu@aptechmongolia.edu.mn">Mike Liu</a>
 * @version $Id: AccountStatusRepository.java 5 2008-09-01 12:08:42Z mikeliucc $
 */
public class AccountStatusRepository {

	private Map<String, AccountStatus> repository;

	private static AccountStatusRepository THIS = new AccountStatusRepository();

	private AccountStatusRepository() { repository = new HashMap<String, AccountStatus>(); }

	public static AccountStatusRepository get() { return THIS; }

	public void disable(String username) { setStatus(username, AccountStatus.DISABLED); }

	public void inactivate(String username) { setStatus(username, AccountStatus.INACTIVE); }

	public void activate(String username) { repository.remove(username); }

	public boolean isDisabled(String username) { return AccountStatus.DISABLED == getStatus(username); }

	public boolean isInactive(String username) { return AccountStatus.INACTIVE == getStatus(username); }

	public boolean isActive(String username) { return getStatus(username) == null; }

	public AccountStatus getStatus(String username) { return repository.get(username); }

	public void setStatus(String username, AccountStatus status) { repository.put(username, status); }
}
